package day0617

/**
  * @program: hadoop
  * @description: 类的比较
  * @author: Qiang.Ye
  * @date: 2019-06-18 06:56
  *
  * Person 名字降序排列，如果名字相同，则按年龄升序排列
  *
  * aaa 13
  * aaa 14
  * rain 14
  *
  *
  **/
case class Person(name:String,age:Int){
  override def toString: String = {
    "name:"+name+",age:"+age
  }

}

object Demo1 {

  def main(args: Array[String]): Unit = {

    implicit object PersonOrdering extends Ordering[Person]{
      override def compare(x: Person, y: Person): Int = {
        x.name == y.name match {
          case  false => x.name.compareTo(y.name)
          case _ => x.age-y.age
        }
      }
    }

    val p1 = new Person("rain",13)
    val p2 = new Person("rain",14)
    import  Ordered._
    println(p1<p2)


  }

}
